package com.baizhi.wxt.controller;

import com.baizhi.wxt.dto.CategoryPageDTO;
import com.baizhi.wxt.entity.Category;
import com.baizhi.wxt.service.CategoryService;
import com.baizhi.wxt.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("category")
@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //一级类别
    @RequestMapping("queryOnePage")
    @ResponseBody
    public CategoryVo queryOnePage(@RequestBody CategoryPageDTO categoryPageDTO){
        return categoryService.queryOnePage(categoryPageDTO.getPage(), categoryPageDTO.getPageSize());
    }

    //二级类别
    @RequestMapping("queryTwoPage")
    @ResponseBody
    public CategoryVo queryTwoPage(@RequestBody CategoryPageDTO categoryPageDTO){
        return categoryService.queryTwoPage(categoryPageDTO.getPage(), categoryPageDTO.getPageSize(), categoryPageDTO.getCategoryId());
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public Map<String,Object> delete(@RequestBody Category category){
        return categoryService.delete(category);
    }

    //添加
    @RequestMapping("add")
    @ResponseBody
    public Map<String,Object> add(@RequestBody Category category){
        return categoryService.add(category);
    }

    //查所有一级类别
    @RequestMapping("queryByLevelsCategory")
    @ResponseBody
    public List<Category> queryByLevelsCategory(int levels){
        return categoryService.queryByLevelsCategory(levels);
    }

    //修改
    @RequestMapping("update")
    @ResponseBody
    public Map<String,Object> update(@RequestBody Category category){
        return categoryService.update(category);
    }

    //根据主键查一个
    @RequestMapping("queryById")
    @ResponseBody
    public Category queryById(int id){
        return categoryService.queryById(id);
    }
}
